<?php

/**
 * This is the model class for table "tabelle_geldgeber_mittelgeber".
 *
 * The followings are the available columns in table 'tabelle_geldgeber_mittelgeber':
 * @property integer $mittelgeber_id
 * @property integer $kategorie_id
 * @property string $mittelgeber_name
 *
 * The followings are the available model relations:
 * @property MittelegberKategorie $kategorie
 */
class Mittelgeber extends CActiveRecord
{
	public $kategorie_search;
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Mittelgeber the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'tabelle_geldgeber_mittelgeber';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('mittelgeber_id ', 'numerical', 'integerOnly'=>true),
			array('mittelgeber_name', 'length', 'max'=>150),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('mittelgeber_id, kategorie_id, mittelgeber_name', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'kategorie' => array(self::BELONGS_TO, 'MittelgeberKategorie', 'kategorie_id'),
			'projekte' => array(self::HAS_MANY, 'Projekte', 'mittelgeber_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'mittelgeber_id' => 'Mittelgeber',
			'kategorie_id' => 'Kategorie',
			'mittelgeber_name' => 'Mittelgeber Name',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->with = array( 'kategorie');
		$criteria->compare('kategorie.kategorie_name',$this->kategorie_id);
		$criteria->compare('mittelgeber_id',$this->mittelgeber_id);
		$criteria->compare('mittelgeber_name',$this->mittelgeber_name,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}